/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-05-25 17:25:04
 * @LastEditTime: 2024-06-29 22:24:51
 * @FilePath: /nest_study/server/src/modules/system/role/entities/role.entity.ts
 */
import { ApiProperty } from "@nestjs/swagger";
import { BaseEntity } from "src/common/entites/base";
import { Column, Entity, JoinTable, ManyToMany, PrimaryGeneratedColumn } from "typeorm";
import { SystemMenuEntity } from "../../menu/entities/menu.entity";

@Entity({
    name: 'sys_role',
    comment: "角色信息表"
})
export class SystemRoleEntity extends BaseEntity {
    @ApiProperty({ type: String, description: '角色Id' })
    @PrimaryGeneratedColumn({ type: 'int', name: 'role_id', comment: '角色Id' })
    public id: number;

    @Column({ type: 'varchar', name: 'role_name', length: 30, comment: '角色名称' })
    public name: string;

    @Column({
        type: 'int', name: 'role_sort', default: 0,
        comment: "排序"
    })
    public sort: number;

    @Column({ type: 'varchar', name: 'role_code', length: 100, comment: '角色权限字符串' })
    public code: string;

    @Column('json', { nullable: true })
    public menuIds: number[];

    @ManyToMany(() => SystemMenuEntity)
    @JoinTable({
        name: "sys_role_menu",
        joinColumn:{
            name:'role_id',
            referencedColumnName:'id'
        },
        inverseJoinColumn:{
            name:'menu_id',
            referencedColumnName:'id'
        }
    })
    menus: SystemMenuEntity[]
}
